//
//  Image.swift
//  downloadImage
//
//  Created by Galaxy on 2022/6/20.
//

import Foundation
import WCDBSwift

final class ImageModel: TableCodable {
    // ID
    var identifier: Int? = nil
    // 图片地址
    var imgUrl: String? = nil
    // 所属id
    var articleId: Int? = nil
    // 是否下载
    var didDownload: Bool? = nil
    
    // 用于获取自增插入后的主键值
    var lastInsertedRowID: Int64 = 0
    // 自增
    var isAutoIncrement: Bool { true }
    enum CodingKeys: String, CodingTableKey {
        typealias Root = ImageModel
        static let objectRelationalMapping = TableBinding(CodingKeys.self) {
            // 设置属性为自增
            BindColumnConstraint(identifier, isPrimary: true)
            BindColumnConstraint(imgUrl, isNotNull: true, defaultTo: "")
            BindColumnConstraint(articleId, isNotNull: true, defaultTo: 0)
            BindColumnConstraint(didDownload, isNotNull: true, defaultTo: false)
        }
        case identifier
        case imgUrl
        case articleId
        case didDownload
    }
}
